package com.zjh.controller;

import com.zjh.pojo.User;
import com.zjh.service.user.UserService;
import com.zjh.service.user.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RegisterServlet", value = "/register")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String email = req.getParameter("email");
        String birthday = req.getParameter("birthday");

        UserService userService = new UserServiceImpl();
        Boolean isRegister = userService.Register(new User(10, username, password, email, birthday));

        if (isRegister) {
            req.getRequestDispatcher("/registerSuccess.jsp").forward(req,resp);
        } else {
            req.getRequestDispatcher("/registerFailed.jsp").forward(req,resp);
        }
    }
}
